package com.zmn.mcc.business.impl.role;


import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.mcc.business.interfaces.role.RoleChangeLogBService;
import com.zmn.mcc.common.dto.role.McRoleChangeLogDIO;
import com.zmn.mcc.common.dto.role.McRoleChangeLogQuery;
import com.zmn.mcc.model.entity.role.McRoleChangeLog;
import com.zmn.mcc.services.interfaces.role.RoleChangeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


/**
 * @author: xuyanghong
 * @since: 2022-07-18
 * description:
 */

@Service
@Slf4j
public class RoleChangeLogBServiceImpl implements RoleChangeLogBService {


    @Autowired
    private RoleChangeLogService roleChangeLogService;

    @Override
    public Integer addMcRoleChangeLog(McRoleChangeLogDIO mcRoleChangeLogDIO) {
        McRoleChangeLog mcRoleChangeLog = BeanMapper.map(mcRoleChangeLogDIO, McRoleChangeLog.class);
        return roleChangeLogService.insert(mcRoleChangeLog);
    }

    @Override
    public Integer modifyMcRoleChangeLog(McRoleChangeLogDIO mcRoleChangeLogDIO) {
        McRoleChangeLog mcRoleChangeLog = BeanMapper.map(mcRoleChangeLogDIO, McRoleChangeLog.class);
        return roleChangeLogService.updateByKey(mcRoleChangeLog);
    }

    @Override
    public List<McRoleChangeLog> listPageMcRoleChangeLog(McRoleChangeLogQuery
                                                                 mcRoleChangeLogQuery) {

        Integer count = roleChangeLogService.countByQuery(mcRoleChangeLogQuery);
        mcRoleChangeLogQuery.setTotalCount(count);
        List<McRoleChangeLog> mcRoleChangeLogList = count > 0 ? roleChangeLogService.listPageByQuery(mcRoleChangeLogQuery) : Collections.emptyList();
        return mcRoleChangeLogList;
    }

    @Override
    public List<McRoleChangeLog> listRoleChangeLog(McRoleChangeLogDIO mcRoleChangeLogDIO) {
        McRoleChangeLogQuery query = new McRoleChangeLogQuery();
        BeanMapper.copy(mcRoleChangeLogDIO, query);
        return roleChangeLogService.listByQuery(query);
    }

    @Override
    public McRoleChangeLog getMcRoleChangeLogById(Long id) {
        return roleChangeLogService.findByKey(id);
    }
}